package com.zbkj.admin.task.giftCard;

import com.zbkj.common.utils.DateUtil;
import com.zbkj.service.service.StoreGiftCardUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 礼品卡失效定时任务
 *
 * @author Swallows
 * @date 2022-08-22 14:55
 */
@Slf4j
@Component
@Configuration
@EnableScheduling
@RequiredArgsConstructor
public class GiftCardOverdueTask {

    private final StoreGiftCardUserService giftCardUserService;

    @Scheduled(fixedDelay = 1000 * 60L) //1分钟同步一次数据
    public void init(){
        log.info("---GiftCardOverdueTask task------produce Data with fixed rate task: Execution Time - {}", DateUtil.nowDateTime());
        try {
            giftCardUserService.overdueTask();
        } catch (Exception e) {
//            e.printStackTrace();
            log.error("GiftCardOverdueTask.task" + " | msg : " + e.getMessage());
        }

    }

    @Scheduled(fixedDelay = 1000 * 60L)
    public void expire() {

        log.info("---GiftCardExpireTask task------produce Data with fixed rate task: Execution Time - {}", DateUtil.nowDateTime());
        try {
            giftCardUserService.expireTask();
        } catch (Exception e) {
            log.error("GiftCardExpireTask.task" + " | msg : " + e.getMessage());
        }
    }
}
